<?php
/*####################
# Kod koj sto se izvrsuva na odredeno vreme
# i vo baza gi smestuva potrebnite podatoci 
# za ponatamosni statistiki...
# 
####################*/

require_once('includes/inc.php');
$connector = new DbConnector();
$qu="SELECT id, woeid FROM gradovi";
$result = $connector->query($qu);
while($row = $connector->fetchArray($result))
{
	$grid=$row['id'];
	$woeid=$row['woeid'];
	
	// source link
	$link="http://weather.yahooapis.com/forecastrss?w=".$woeid."&u=c";
	
	// zemanje na parametri od
	$src=file_get_contents($link);
	
	//za:	
	// brzina na veter
	$vetar=getAttrib("wind","speed",$src);
	
	//vlaznost
	$vlaznost=getAttrib("atmosphere","humidity",$src);
	
	// vidlivost
	$vid=getAttrib("atmosphere","visibility",$src);
	
	//pritisok
	$pritisok=getAttrib("atmosphere","pressure",$src);
	
	//temperatura
	$temp=getAttrib("condition","temp",$src);
	
	//kod za vremenski uslovi
	$kod=getAttrib("condition","code",$src);
	
	$datum=date('Y-m-d');
	
	$vreme=date('H:00:00');
	
	$connectorx = new DbConnector();
	$qux="INSERT INTO istorija(grid,datum,vreme,temp,vlaznost,pritisok,vetar,vid,cond) 
	VALUES($grid,'$datum','$vreme','$temp',$vlaznost,$pritisok,$vetar,$vid,$kod)";
	
	$connectorx->query($qux);
	
}
?>